local skel = fk.CreateSkill{
  name = "tea__kuitian",
  tags = { Skill.Compulsory }
}
Fk:loadTranslationTable{
  ["tea__kuitian"] = "窥天",
  [":tea__kuitian"] = "锁定技，牌堆顶第X张牌始终对你可见（X为你的体力上限）。你可以使用或打出此牌，然后本轮你可见牌前移一位。",
  ["tea__kuitian_mod-round"] = "窥天",
  ["@$tea__kuitian_mark"] = "窥天",
}
---@param player ServerPlayer|Player
---@param room Room|AbstractRoom
---@return integer
local getCardId = function (player, room)
  local maxHp = player.maxHp
  local modNum = math.max(maxHp - player:getMark("tea__kuitian_mod-round"))
  return room.draw_pile[modNum] or 0
end
---@type ViewAsSkillSpec
local kuitian = {
  expand_pile = function (self, player)
    return { getCardId(player, Fk:currentRoom()) }
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and to_select == getCardId(player, Fk:currentRoom())
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return end
    local c = Fk:getCardById(cards[1])
    c.skillName = skel.name
    return c
  end,
  before_use = function (self, player, use)
    player.room:addPlayerMark(player, "tea__kuitian_mod-round", 1)
  end,
}
---@type TrigSkelSpec<MoveCardsFunc>
local kuitian_re = {
  can_refresh = function (self, event, target, player, data)
    if not player:hasSkill(skel.name, true) then return end
    for _, move in ipairs(data) do
      if move.toArea == Card.DrawPile then return true end
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.DrawPile then
          return true
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local cid = getCardId(player, room)
    if cid ~= 0 then
      room:setPlayerMark(player, "@$tea__kuitian_mark", {cid})
    end
  end
}
---@type TrigSkelSpec<TrigFunc>
local kuitian_re2 = {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name, true)
  end,
  on_refresh = kuitian_re.on_refresh,
}
skel:addEffect("viewas", kuitian)
skel:addEffect(fk.AfterCardsMove, kuitian_re)
skel:addEffect(fk.GameStart, kuitian_re2)
return skel